package com.habdqn.studentmanager.bean.ajax;

import com.github.pagehelper.PageInfo;
import com.habdqn.studentmanager.bean.Bean;

/**
 * @author Fan
 * 
 *         2017年7月16日
 * 
 */
public class Page extends Bean {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    /**
     * 当前页
     */
    private Integer pageNum = 1;

    /**
     * 每页的数量
     */
    private Integer pageSize = 10;

    /**
     * 总记录数
     */
    private Long total;

    /**
     * 总页数
     */
    private Integer pages;

    /**
     * @return the pageNum
     */
    public Integer getPageNum() {
        return pageNum;
    }

    /**
     * @return the pageSize
     */
    public Integer getPageSize() {
        return pageSize;
    }

    /**
     * @return the total
     */
    public Long getTotal() {
        return total;
    }

    /**
     * @return the pages
     */
    public Integer getPages() {
        return pages;
    }

    /**
     * @param pageNum
     *            the pageNum to set
     */
    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    /**
     * @param pageSize
     *            the pageSize to set
     */
    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    /**
     * @param total
     *            the total to set
     */
    public void setTotal(Long total) {
        this.total = total;
    }

    /**
     * @param pages
     *            the pages to set
     */
    public void setPages(Integer pages) {
        this.pages = pages;
    }
    
    /**
     * 判断分页参数是否为空, 否则给个默认值
     */
    public void reset() {
        
        if (null == pageNum) {
            pageNum = 1;            
        }
        
        if (null == pageSize) {
            pageSize = 10;            
        }
    }
    
    /**
     * 将pageInfo转换成page
     * 
     * @param pageInfo
     * @return
     */
    public static Page valueOf(PageInfo<?> pageInfo) {
        Page page = new Page();
        page.setPageNum(pageInfo.getPageNum());
        page.setPageSize(pageInfo.getPageSize());
        page.setPages(pageInfo.getPages());
        page.setTotal(pageInfo.getTotal());
        return page;
    }
    
    /**
     * 快速构建分页对象
     * @param pageNum
     * @param pageSize
     * @return
     */
    public static Page build(Integer pageNum, Integer pageSize) {
        Page page = new Page();
        page.setPageNum(pageNum);
        page.setPageSize(pageSize);
        return page;
    }
}
